Cube = require('../model/cube').Cube
Surface = require('../model/cube').Surface
CubeLight = require('../model/cube').CubeLight
Runtime = require('../model/runtime').Runtime

runtime = new Runtime()

cubes = []
for i in [1..3]
	cubes.push(new Cube())

cubes[0].surfaces[0].info.io = Surface.type.OUT
cubes[0].surfaces[0].info.linkTo = cubes[1].surfaces[0]
cubes[1].surfaces[0].info.io = Surface.type.IN
cubes[1].surfaces[0].info.linkTo = cubes[0].surfaces[0]


cubes[2].surfaces[1].info.io = Surface.type.OUT
cubes[2].surfaces[1].info.linkTo = cubes[1].surfaces[1]
cubes[1].surfaces[1].info.io = Surface.type.IN
cubes[1].surfaces[1].info.linkTo = cubes[2].surfaces[1]

cubes[0].surfaces[2].info.io = Surface.type.IN
cubes[0].surfaces[2].info.linkTo = cubes[2].surfaces[2]
cubes[2].surfaces[2].info.io = Surface.type.OUT
cubes[2].surfaces[2].info.linkTo = cubes[0].surfaces[2]

cubes[0].code = "console.log('cube ', 0); this.port[0] = this.port[2];"
cubes[1].code = "console.log('cube ', 1);"
cubes[2].code = "console.log('cube ', 2); this.port[2] = 5;"


console.log runtime.startGame cubes, (err, roundCount) ->
	throw err if err?
	console.log "#{roundCount} finish"

setTimeout () ->
	runtime.stopGame()
, 1000